Rules for Naming JS Variables:
-
Variable names can only contain
letters, digits,
underscores,
and dollar signs.
For example, $my_1stVariable
-
Variables must begin with a
letter, underscore, or
dollar sign.
For example, $name
, _name
or
name
-
Variable names are case sensitive.
For example, myVar
and myvar
are different
variables.
-
Variable names should not be JavaScript
reserved words.
For example, you cannot use words like var
,
const
, or let
as variable names.
5 legal variable names:
- camelCaseName.
- $price
- _age.
- variable123.
- [legal_variable.]
5 illegal variable names:
- 123name
- name-age
- var,const,let
- true-or-false-value.
- @name